package net.chery.exec;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @author gai
 * 连接电池溯源系统数据库
 */
@Slf4j
@Component
@ConfigurationProperties(prefix = "other.datasource."+ BatteryExec.KEY)
public class BatteryExec extends BaseExec {
    public static final String KEY="battery";

    @Scheduled(fixedDelay = 10*60*1000)
    public void closeDatasource(){
        if(!dataSource.isClosed()&&System.currentTimeMillis()-initTime>20*60*1000&&!isActive()){
            dataSource.close();
            log.warn("battery datasource has be closed");
        }
    }
}
